package kr.co.m2soft.model.page.elements
{
	import kr.co.m2soft.model.CommonModel;
	import kr.co.m2soft.model.elements.FA;
	import kr.co.m2soft.model.elements.LA;
	
	import mx.collections.ArrayCollection;

	public class Figure extends PGElement implements IFigure
	{
		
		private var commonModel:CommonModel = CommonModel.getInstance();
		
		private var _lid:int;
		private var _fid:int;
		
		private var _sx:Number;
		private var _sy:Number;
		private var _ex:Number;
		private var _ey:Number;
		
		private var _la:LA;
		private var _fa:FA;
		
		private var _fc:String = "#000000";
		private var _al:int = 0;
		private var _pt:int = 0;
		
		private var _st:int;
		private var _wd:Number;
		private var _lc:String = "#0066CC";
		private var _ap:int = 0;
		private var _dt:String;
		private var _LAList:ArrayCollection;
		private var _FAList:ArrayCollection;
		
		
		public function Figure()
		{
		}
		override public function parser():void
		{
			super.parser();
			_LAList = commonModel.mml.head.LAList;
			_FAList = commonModel.mml.head.FAList;
			_lid = dataProvider.hasOwnProperty("@lid") ? dataProvider.@tid : _lid;
			_fid = dataProvider.hasOwnProperty("@fid") ? dataProvider.@tid : _fid;
			if(_lid != 0){
				try{
					_la = getLA(_lid);
				}catch(e:RangeError){}
				
				_st = la.st;
				_wd = la.wd;
				_lc = la.lc;
				_ap = la.ap;

			}
			if(_fid != 0){
				try{
					_fa = getFA(_fid);
				}catch(e:RangeError){}
				
				_fc = fa.fc;
				_al = fa.al;
				_pt = fa.pt;
				
			}
			
			_st = dataProvider.hasOwnProperty("@st") ? dataProvider.@st : _st;
			_wd = dataProvider.hasOwnProperty("@wd") ? dataProvider.@wd : _wd;
			_lc = dataProvider.hasOwnProperty("@lc") ? dataProvider.@lc : _lc;
			_ap = dataProvider.hasOwnProperty("@ap") ? dataProvider.@ap : _ap;
			
			_fc = dataProvider.hasOwnProperty("@fc") ? dataProvider.@fc : _fc;
			_la = dataProvider.hasOwnProperty("@la") ? dataProvider.@la : _la;
			_pt = dataProvider.hasOwnProperty("@pt") ? dataProvider.@pt : _pt;
			
			_sx = dataProvider.hasOwnProperty("@sx") ? dataProvider.@sx : _sx;
			_sy = dataProvider.hasOwnProperty("@sy") ? dataProvider.@sy : _sy;
			_ex = dataProvider.hasOwnProperty("@ex") ? dataProvider.@ex : _ex;
			_ey = dataProvider.hasOwnProperty("@ey") ? dataProvider.@ey : _ey;
			
		}

		private function getLA(index:int):LA
		{
			for each(var item:LA in commonModel.mml.head.LAList){
				if(index == item.eid){
					break;
				}
			}
			return item;
		}
		private function getFA(index:int):FA
		{
			for each(var item:FA in commonModel.mml.head.FAList){
				if(index == item.eid){
					break;
				}
			}
			return item;
		}
		public function get sx():Number
		{
			return _sx;
		}

		public function set sx(value:Number):void
		{
			_sx = value;
		}

		public function get sy():Number
		{
			return _sy;
		}

		public function set sy(value:Number):void
		{
			_sy = value;
		}

		public function get ex():Number
		{
			return _ex;
		}

		public function set ex(value:Number):void
		{
			_ex = value;
		}
		
		public function get ey():Number
		{
			return _ey;
		}
		
		public function set ey(value:Number):void
		{
			_ey = value;
		}
		
		public function get lid():int
		{
			return _lid;
		}

		public function set lid(value:int):void
		{
			_lid = value;
		}

		public function get fid():int
		{
			return _fid;
		}

		public function set fid(value:int):void
		{
			_fid = value;
		}

		[Inspectable(defaultValue="#000000" )]
		public function get fc():String
		{
			return _fc;
		}

		public function set fc(value:String):void
		{
			_fc = value;
		}

		public function get pt():int
		{
			return _pt;
		}

		public function set pt(value:int):void
		{
			_pt = value;
		}

		public function get la():LA
		{
			return _la;
		}

		public function set la(value:LA):void
		{
			_la = value;
		}

		public function get fa():FA
		{
			return _fa;
		}

		public function set fa(value:FA):void
		{
			_fa = value;
		}

		public function get st():int
		{
			return _st;
		}

		public function set st(value:int):void
		{
			_st = value;
		}

		public function get wd():Number
		{
			return _wd;
		}

		public function set wd(value:Number):void
		{
			_wd = value;
		}

		public function get lc():String
		{
			return _lc;
		}

		public function set lc(value:String):void
		{
			_lc = value;
		}

		public function get ap():int
		{
			return _ap;
		}

		public function set ap(value:int):void
		{
			_ap = value;
		}

		public function get dt():String
		{
			return _dt;
		}
		public function set dt(value:String):void
		{
			_dt = value;
		}


	}
}